home *** CD-ROM | disk | FTP | other *** search
- /*
- * smupcdev.c
- * 17 June 1993 by Mark C Smith • University of Michigan
- * Copyright (c) 1993 Mark C Smith
- */
- #include <Dialogs.h>
- #include <Devices.h>
- #include <Memory.h>
- #include <GestaltEqu.h>
- #include "smupdate.h"
-
- pascal long main( short msg, short item, short numitems, short id, EventRecord *erp,
- long value, DialogPtr dlp );
-
-
- typedef struct {
- Boolean smst_on;
- GestaltProcPtr smst_gestproc;
- } smstatus;
-
-
- pascal long
- main( short msg, short item, short numitems, short id, EventRecord *erp,
- long value, DialogPtr dlp )
- {
- short type;
- Handle hdl;
- Rect r;
- long response;
- smstatus **smsth;
-
- smsth = (smstatus **)value;
-
- switch ( msg ) {
- case initDev:
- /*
- * make sure we can talk to our patch
- */
- if ( Gestalt( sSmUpdate, &response ) != noErr ) {
- return( cdevGenErr ); /* XXX lame error return */
- }
- if (( smsth = (smstatus **)NewHandle( sizeof( smstatus ))) == NULL ) {
- return( cdevMemErr );
- }
- (*smsth)->smst_gestproc = (GestaltProcPtr)response;
- ((*smsth)->smst_gestproc)( sSmStatus, &response );
- (*smsth)->smst_on = ( response != 0 );
-
- if ( (*smsth)->smst_on ) {
- GetDItem( dlp, numitems + 1, &type, &hdl, &r );
- SetCtlValue( (ControlHandle)hdl, 1 );
- }
- value = (long)smsth;
- break;
- case closeDev:
- DisposeHandle( (Handle)value );
- break;
- case hitDev:
- if ( item == numitems + 1 ) {
- GetDItem( dlp, item, &type, &hdl, &r );
- ((*smsth)->smst_gestproc)( (*smsth)->smst_on ? sSmOff : sSmOn, &response );
- (*smsth)->smst_on = !(*smsth)->smst_on;
- SetCtlValue( (ControlHandle)hdl, 1 - GetCtlValue( (ControlHandle)hdl ));
- }
- break;
- }
-
- return( value );
- }
-